﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>单据</title>

    <link href="../../../Scripts/easyUI145/themes/icon.css" rel="stylesheet" type="text/css" />
    <link href="../../../Scripts/easyUI145/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <script src="../../../Scripts/easyUI145/jquery.min.js" type="text/javascript"></script>
    <script src="../../../Scripts/easyUI145/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../../Comm/Gener.js" type="text/javascript"></script>
    <script src="DDLBar.js" type="text/javascript"></script>
    <script src="../../EnumLab.js"></script>
    <script src="../../../Admin/Admin.js"></script>

    <script type="text/javascript">

        $(function () {

            InitBar("Bill");

        });

        function Save() {

          //  debugger;

            $("#Msg").html("正在创建,请稍后......");

            var name = document.getElementById("TB_Name").value;
            var no = document.getElementById("TB_No").value;
            //  var noOrg = document.getElementById("TB_No_Org").value;
            var pTable = document.getElementById("TB_PTable").value;

            if (name == "" || no == "" || pTable == "") {
                $("#Msg").html("");
                alert('@请输入必填的字段.');
                return;
            }

            //求出来该表单所在的 菜单，菜单所在大模块，模块所在的系统，把系统编号计算出来.
            var frmID = this.GetQueryString("FrmID");

            // 或的系统编号.
            var moduleNo = this.GetQueryString("ModuleNo");
            var module = new Entity("BP.CCFast.CCMenu.Module", moduleNo);

            //1. 创建单据.
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_CCFormDesigner");
            handler.AddFormData();
            handler.AddUrlData();
            handler.AddPara("FK_FrmSort", module.SystemNo);
            handler.AddPara("EntityType", 1); //单据格式.
            var data = handler.DoMethodReturnString("NewFrmGuide_Create");
            if (data.indexOf('err@') >= 0) {
                $("#Msg").html("<font color=red>" + data + "</font>");
                return;
            }

            //为单据创建从表数据，即把实体表中的字段copy到单据的从表中
            handler = new HttpHandler("BP.CCBill.WF_CCBill_Admin_Collection");
            handler.AddPara("DictFrmID", frmID);
            handler.AddPara("BillFrmID", no);
            var data = handler.DoMethodReturnString("Bill_Save");
            if (data.indexOf('err@') >= 0) {
                $("#Msg").html("<font color=red>" + data + "</font>");
                return;
            }

            //3. 为单据创建方法. 新建单据
            var method = new Entity("BP.CCBill.Template.MethodBill");
            method.MethodModel = "Bill"; //方法模式.
            //   method.MyPK = frmID + "_" + no; // 单据ID.
            method.Name = name;
            method.GroupID = GetQueryString("GroupID"); //方法分组.
            method.Mark = "Search"; //标记链接到查询页面.
            method.FrmID = frmID;
            method.UrlExt = no; // "../CCBill/MyBill.htm";
            method.Tag1 = no;
            method.Icon = "icon-note"; //新建icon.
            method.Idx = 0;
            method.IsCanBatch = 1;
            method.Insert();

            var methodNewNo = method.No;


            //4. 创建菜单.放到与单据的平行的目录下.
            var menu = new Entity("BP.CCFast.CCMenu.Menu");
            menu.ModuleNo = moduleNo; //模块编号.
            menu.SystemNo = module.SystemNo; //系统编号.
            menu.Name = name;
            menu.UrlExt = "../CCBill/SearchBill.htm?FrmID=" + no + "&From=Dict&PFrmID=" + frmID;
            menu.MenuModel = MethodModel.Bill; //类型为
            menu.Icon = "icon-note"; //单据ICON.

            // 把他们都设置为 dictNo.
            menu.Mark = "BillDictSearch"; //单据表单ID。
            menu.Tag1 = no; //单据表单ID。
            menu.FrmID = frmID;
            method.Idx = 1;
            menu.Insert();

            var msg = "提示:(请仔细阅读)";
            msg += "\t\n 1. 您创建的是一个单据, fast会您创建一个名为[" + name + "]的链接在实体卡片上。";
            msg += "\t\n 2. 同时fast也在当前实体的菜单上创建了。";


            SetHref("../../../Comm/En.htm?EnName=BP.CCBill.Template.MethodBill&No=" + methodNewNo);
        }

        function GenerPinYin() {

            //是否是全拼.
            var isQuanPin = 0;
            if (document.getElementById("RB_PinYinModel_0").checked == true)
                isQuanPin = 1;

            // var name = $('#TB_Nam').val();
            var name = document.getElementById("TB_Name").value;
            if (name == "")
                return;

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_CCFormDesigner");
            handler.AddPara("IsQuanPin", isQuanPin);
            handler.AddPara("TB_Name", encodeURIComponent(name));
            var data = handler.DoMethodReturnString("NewFrmGuide_GenerPinYin");

            $("#Msg").html("");

            if (data.indexOf('err@') >= 0) {
                $("#Msg").html("<font color=red>" + data + "</font>");
                return;
            }

            $('#TB_No').val("Bill_" + data);
            $('#TB_PTable').val("Bill_" + data);

        }
    </script>
</head>
<body>
    <form id="CCForm">
        <div id="bar">
        </div>
        <fieldset>
            <legend>创建单据表单 </legend>
            <table>
                <tr>
                    <td>单据名称 </td>
                    <td>  <input type="text" value="" id="TB_Name" name="TB_Name" onblur="GenerPinYin()" /></td>
                    <td>单据编号 </td>
                    <td>
                        <input type="text" value="" id="TB_No" name="TB_No" />

                        <input id="RB_PinYinModel_0" type="radio" name="RB_PinYinModel" value="0" checked="checked" onclick="GenerPinYin()" /><label for="RB_PinYinModel_0" onclick="GenerPinYin()">全拼</label>
                        <input id="RB_PinYinModel_1" type="radio" name="RB_PinYinModel" value="1" onclick="GenerPinYin()" /><label for="RB_PinYinModel_1" onclick="GenerPinYin()">简拼</label>

                    </td>
                </tr>

                <tr>
                    <td> 表单类型 </td>
                    <td>
                        <select id="DDL_FrmType">
                            <option value="0" selected="selected">经典表单</option>
                            <option value="8">开发者表单</option>
                        </select>
                    </td>
                    <td> 存储表</td>
                    <td>
                        <input type="text" value="" id="TB_PTable" name="TB_PTable" />
                        <!--<input type="text" id="TB_PTable_Org" name="TB_PTable_Org" style="width: 100%;" hidden=hidden />-->
                    </td>
                </tr>
                <tr>
                    <td> 列表模式</td>
                    <td colspan="3">
                        <input id="RB_ListModel_0" type="radio" name="RB_ListModel" value="0" /><label for="RB_ListModel_0">编辑模式</label>
                        <input id="RB_ListModel_1" type="radio" name="RB_ListModel" value="1" checked="checked" /><label for="RB_ListModel_1">视图模式</label>
                    </td>
                </tr>

                <tr>
                    <td colspan="4">
                        备注：更多的属性在创建后可以修改，比如：存储表，导入字段，表单模式。
                    </td>
                </tr>
            </table>

            <!--<input type="button" id="Btn_Save" name="Btn_Save" value="执行创建" onclick="Save();" />-->
            <div id="Msg"></div>

            <legend> 什么是单据？ </legend>
            <ul>
                <li> 单据就是依赖与实体存在流水性质的记账凭证。 </li>
                <li> 比如：出门证、介绍信、证明函。 </li>
                <li> 比如：出库单、入库单。 </li>
                <li> 创建单据后，不需要审批，或者简单的审批就可以设置为入库状态的数据。 </li>
            </ul>
        </fieldset>

    </form>
</body>
</html>
